package servlet;

import java.io.IOException;
import java.sql.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import db.DB;
import model.lyTable;
import model.User;

public class AddServlet extends HttpServlet{
  @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	  req.setCharacterEncoding("gb2312");
	  resp.setContentType("gb2312");
	  String title=req.getParameter("title");
	  String content=req.getParameter("content");
	  User user=(User)req.getSession().getAttribute("user");
	  lyTable ly=new lyTable();
	  ly.setUserId(user.getId());
	  ly.setDate(new Date(System.currentTimeMillis()));
	  ly.setTitle(title);
	  ly.setContent(content);
	  if(new DB().addInfo(ly)){
		  resp.sendRedirect("success.jsp");
	  }
}
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
}
